<template>
	<view>
		<view class="list">
			<view v-for="(item,i) in goodList" :key="i"  @click="gogooddetails(item)">
				<my-goods :item="item"></my-goods>
			</view>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				// 请求参数对象
				queryObj: {
					query: '',
					cid: '',
					pageNO: 1,
					pageSize: 10
				},
				goodList: [],
				total: 0,
				isloading:false
			};
		},
		onLoad(options) {
			// console.log(options)
			this.queryObj.query = options.query || ''
			this.queryObj.cid = options.cid || ''
			console.log(this.queryObj)
			this.getGoodList()
		},
		methods: {
			async getGoodList(cb) {
				this.isloading = true
				const {
					data: listData
				} = await uni.$http.get('searchlist2?' + this.queryObj)
				this.isloading = false
				// 只要数据请求完毕，就立即按需调用 cb 回调函数  
				cb && cb()
				// 为数据赋值：通过展开运算符的形式，进行新旧数据的拼接
				this.goodList = [...this.goodList,...listData]
				this.total = listData.length
			},
			gogooddetails(item){
				console.log(item)
				 uni.navigateTo({
				 	url:"/subpkg/goods_detail/goods_detail?goods_id="+item.goods_id
				 })
			}
			
		},
		// 上拉触底的事件
		onReachBottom(){
			//当前的页码值 * 每页显示多少条数据 >= 总数条数,表示数据加载完毕
			if(this.queryObj.pageNO*this.queryObj.pageSize>=this.total){
				return uni.$showMsg('数据加载完毕')
			}
			//如果节流阀关闭，则不执行触底加载事件
			if(this.isloading){
				return
			}
			this.queryObj.pageNO+=1
			this.getGoodList()			
		},
		// 下拉刷新的事件
		onPullDownRefresh(){
			this.goodList= []
			this.total=0
			this.isloading=false
			this.queryObj.pageNO=1
			this.getGoodList(()=>{
				uni.stopPullDownRefresh()
			})
		}
	}
</script>

<style lang="less">

</style>
